﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace DBManager
{
    public static class Logger
    {
        public const string ModuleName = "DBManager";
        public static void Write(string strMessage)
        {
            Write(strMessage, "IO");
        }
        public static void Write(string strMessage, string Catagory)
        {
            try
            {
                string strTime = System.DateTime.Now.ToString("yyyy-MM-dd");
                string path = System.IO.Directory.GetCurrentDirectory();
                if (Directory.Exists(path + "\\Log") == false)
                    Directory.CreateDirectory(path + "\\Log");

                string strName = path + "\\Log\\" + ModuleName + strTime + ".log";
                StreamWriter wrt = null;
                if (File.Exists(strName) == false)
                    wrt = File.CreateText(strName);
                else
                    wrt = new StreamWriter(strName, true);
                strMessage = strMessage.Replace("\r\n", " ");
                string strLog = System.DateTime.Now.ToString("HH:mm:ss") + "\t" + Catagory + "\t" + strMessage;
                wrt.WriteLine(strLog);
                wrt.Close();
            }
            catch (Exception)
            {
            }
        }
    }
}
